package cn.stylefeng.guns.modular.ry600.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.stylefeng.roses.core.base.controller.BaseController;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;

import cn.stylefeng.guns.core.log.LogObjectHolder;

import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;

import cn.stylefeng.guns.modular.system.model.Orderitem;
import cn.stylefeng.guns.modular.ry600.service.IOrderitemService;

/**
 * 连锁订单明细表控制器
 *
 * @author fengshuonan
 * @Date 2018-12-14 11:47:53
 */
@Controller
@RequestMapping("/orderitem")
public class OrderitemController extends BaseController {

    private String PREFIX = "/ry600/orderitem/";

    @Autowired
    private IOrderitemService orderitemService;

    /**
     * 跳转到连锁订单明细表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "orderitem.html";
    }

    /**
     * 跳转到添加连锁订单明细表
     */
    @RequestMapping("/orderitem_add")
    public String orderitemAdd() {
        return PREFIX + "orderitem_add.html";
    }

    /**
     * 跳转到修改连锁订单明细表
     */
    @RequestMapping("/orderitem_update/{orderitemId}")
    public String orderitemUpdate(@PathVariable Integer orderitemId, Model model) {
        Orderitem orderitem = orderitemService.selectById(orderitemId);
        model.addAttribute("item",orderitem);
        LogObjectHolder.me().set(orderitem);
        return PREFIX + "orderitem_edit.html";
    }

    /**
     * 获取连锁订单明细表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return orderitemService.selectList(null);
    }

    /**
     * 新增连锁订单明细表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Orderitem orderitem) {
        orderitemService.insert(orderitem);
        return SUCCESS_TIP;
    }

    /**
     * 删除连锁订单明细表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer orderitemId) {
        orderitemService.deleteById(orderitemId);
        return SUCCESS_TIP;
    }

    /**
     * 修改连锁订单明细表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Orderitem orderitem) {
        orderitemService.updateById(orderitem);
        return SUCCESS_TIP;
    }

    /**
     * 连锁订单明细表详情
     */
    @RequestMapping(value = "/detail/{orderitemId}")
    @ResponseBody
    public Object detail(@PathVariable("orderitemId") Integer orderitemId) {
        return orderitemService.selectById(orderitemId);
    }
    
    @RequestMapping(value = "/selectByMsg")
    @ResponseBody
    public Object selectByMsg(HttpServletRequest request, HttpServletResponse response) {
    	Integer page = Integer.valueOf(request.getParameter("page"));
		Integer rows = Integer.valueOf(request.getParameter("rows"));
    	Map<String, Object> msg=this.setMap(request);
    	PageHelper.startPage(page, rows);
    	Object result=orderitemService.selectByMsg(msg);
    	
    	return result;
        
    }
    
    public Map<String,Object> setMap(HttpServletRequest request){
    	Map<String, Object> msg = new HashMap<String, Object>();
    	String searchKey = request.getParameter("searchKey");
		String searchWord = request.getParameter("searchWord");
		if (!StringUtils.isBlank(searchKey) && !StringUtils.isBlank(searchWord)) {
			msg.put(searchKey.trim(), searchWord.trim());
		}
		return msg;
    }
    
}
